
unit fmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dxSkinsCore, dxSkinOffice2007Black, dxSkinPumpkin,
  dxSkinsDefaultPainters, cxLookAndFeels, dxSkinsForm, cxGraphics,
  cxControls, cxLookAndFeelPainters, cxContainer, cxEdit, cxGroupBox,
  Menus, StdCtrls, cxButtons, dxSkinsdxStatusBarPainter, dxStatusBar,
  dxorgchr, Grids, BaseGrid, AdvGrid, GradientLabel, ComCtrls, AdvProgr,
  AdvTabSet, AdvPicture, ToolPanels, ExtCtrls, AdvPageControl, AdvNavBar,
  PictureList, AdvGlowButton, ImgList, AdvGlassButton, AdvOfficeHint, DM,
  rtflabel, ActnList;

type
  TMainForm = class(TForm)
    SkinController: TdxSkinController;
    grpControl: TcxGroupBox;
    StatusBar: TdxStatusBar;
    btnClients: TAdvGlowButton;
    btnOrders: TAdvGlowButton;
    btnProducts: TAdvGlowButton;
    btnHome: TAdvGlowButton;
    AdvOfficeHint: TAdvOfficeHint;
    btnWWW: TAdvGlowButton;
    btnAnalitic: TAdvGlowButton;
    lblAbout: TLabel;
    lblOptions: TLabel;
    lblTest: TLabel;
    ActionList1: TActionList;
    actClient: TAction;
    actOrder: TAction;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnHomeClick(Sender: TObject);
    procedure lblOptionsClick(Sender: TObject);
    procedure lblOptionsMouseEnter(Sender: TObject);
    procedure lblOptionsMouseLeave(Sender: TObject);
    procedure lblAboutMouseEnter(Sender: TObject);
    procedure lblAboutMouseLeave(Sender: TObject);
    procedure lblTestClick(Sender: TObject);
    procedure btnProductsClick(Sender: TObject);
    procedure actClientExecute(Sender: TObject);
    procedure actOrderExecute(Sender: TObject);
  private
    { Private declarations }
    function CheckConnection: boolean;
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation
{$R *.dfm}

uses
  test, fmFirmModule, fmOptionModule, fmPriceModule, fmClientModule, fmOrderModule, Core;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  dmMain := TDMdl.Create(self);
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
  dmMain.Free;
end;

procedure TMainForm.btnHomeClick(Sender: TObject);
begin
  if not CheckConnection then
    Exit;

  with TFirmModuleForm.Create(self) do
  try
    Show;
  finally
//    Free;
  end;
end;

function TMainForm.CheckConnection: boolean;
begin
  Result := dmMain.Init;

  if Result then
  begin
    TdxStatusBarStateIndicatorPanelStyle(StatusBar.Panels[0].PanelStyle).Indicators[0].IndicatorType := sitGreen;
    StatusBar.Panels[1].Text := Format('%s', [dmMain.UserName]);
  end else
    TdxStatusBarStateIndicatorPanelStyle(StatusBar.Panels[0].PanelStyle).Indicators[0].IndicatorType := sitOff;
end;

procedure TMainForm.lblOptionsClick(Sender: TObject);
begin
  if not CheckConnection then
    Exit;
    
  with TOptionModuleForm.Create(self) do
  try
    ShowModal;
  finally
    Free;
  end;
end;

procedure TMainForm.lblOptionsMouseEnter(Sender: TObject);
begin
  lblOptions.Font.Style := lblOptions.Font.Style + [fsUnderline];
end;

procedure TMainForm.lblOptionsMouseLeave(Sender: TObject);
begin
  lblOptions.Font.Style := lblOptions.Font.Style -[fsUnderline];
end;

procedure TMainForm.lblAboutMouseEnter(Sender: TObject);
begin
  lblAbout.Font.Style := lblAbout.Font.Style + [fsUnderline];
end;

procedure TMainForm.lblAboutMouseLeave(Sender: TObject);
begin
  lblAbout.Font.Style := lblAbout.Font.Style - [fsUnderline];
end;

procedure TMainForm.lblTestClick(Sender: TObject);
begin
  with TTestForm.Create(self) do
  try
    Show;
  finally
//    Free;
  end;
end;

procedure TMainForm.btnProductsClick(Sender: TObject);
begin
  if not CheckConnection then
    Exit;

  with TPriceModuleForm.Create(self) do
  try
    Show;
  finally
//    Free;
  end;
end;

procedure TMainForm.actClientExecute(Sender: TObject);
begin
  if not CheckConnection then
    Exit;

  with TClientModuleForm.Create(self) do
  try
    Show;
  finally
//    Free;
  end;
end;

procedure TMainForm.actOrderExecute(Sender: TObject);
begin
  if not CheckConnection then
    Exit;

  with TOrderModuleForm.Create(self) do
  try
    Show;
  finally
//    Free;
  end;
end;

end.
